<?php 
namespace Api\Controller;
class YgclController extends CommonController{
	
	protected $m;
	protected $xiaoqu;
	protected $class;
	protected $classtype;
	protected $lesson;
	protected $order;
	protected $tiyan;
	protected $dianzai;
	protected $teacher;
	protected $video;
	protected $qitatiyan;
	protected $termService;
	
	function _initialize() {
		parent::_initialize();
		$this->m = D('YgclTerm');
		$this->xiaoqu = D('YgclDistrict');
		$this->class = D('YgclClass');
		$this->classtype = D('YgclClassType');
		$this->lesson = D('YgclLesson');
		$this->order = D('YgclOrder');
		$this->tiyan = D('YgclTiyan');
		$this->dianzai = D('YgclDianzai');
		$this->teacher = D('YgclTeacherContents');
		$this->video = D('MaterialVideos');
		$this->qitatiyan = D('YgclQitatiyan');
		$this->termService = D('Ygcl','Service');
	}
	
	public function checklaosheng(){
		$student = I('student');
		$tel = I('tel');
		$info = $this->checkls($student, $tel);
		if($info){
			$data = array('status'=>1,'data'=>$info);
		}else{
			$data = array('status'=>0,'data'=>"");
		}
		$this->ajaxReturn($data);
	}
	
	public function check_laosheng_by_xuenian($xnid,$student,$tel){
		$map = array(
				'student' => $student,
				'tel' => $tel,
				'xuenian' => array('like','%X'.$xnid.'N%')
		);
		$info = M('LessonStudentRelation')->where($map)->order('id desc')->find();
		if($info){
			return $info;
		}else{
			return false;
		}
	}
	
	//判断新生还是老生
	public function checkls($student,$tel){
		
		$arr = array();
		//$xuenian = R('Api/Termtime/get_term_time_now_and_past');
		//foreach ($xuenian as $xn){
		//	$info = $this->check_laosheng_by_xuenian($xn['id'], $student, $tel);
		//	if($info){
		//		$arr = array('type'=>'lsr','id'=>$info['id']);
		//		break;
		//	}
		//}
		//从LessonStudentRelation表中查看是否有记录
		$map = array('student'=>$student,'tel'=>$tel);
		$info = M('LessonStudentRelation')->where($map)->order('id desc')->find();
		if($info){
			$arr = array('type'=>'lsr','id'=>$info['id']);
		}else{
			$data = M('YgclOldstudent')->where($map)->find();
			if($data){
				$arr = array('type' => 'oldstu','id' => $data['id']);
			}
		}

		if($arr){
			return $arr;
		}else{
			return false;
		}
	}
	
	//获取关联的备注
	public function get_remark_relation($tid,$ctid){
		return M('YgclClassTypeRemark')->where(array('tid'=>$tid,'ctid'=>$ctid))->getField('remark');
	}
	
	
	
	/**
	 * 获取暑期班课程的学期、课程的收费信息
	 * @param unknown $term
	 * @param unknown $classtype
	 * @param unknown $status
	 */
	public function get_xuqi_lesson_summer($tid,$lid,$status){
		$ct = $this->lesson->where(array('id'=>$lid))->relation(true)->find();
		$classtype = $ct['classtype'];
	
		$classtype['target1'] == $classtype['target2'] ? $tar = $classtype['target1'].'岁' : $tar = $classtype['target1'].'-'.$classtype['target2'].'岁';
	
		$term = $this->m->where(array('id'=>$tid))->find();
	
			//一个学年
		$total = $classtype['total'];
		$minititle = $term['title'];
		$html = $minititle.',学费'.$total.'元。';

		$minihtml = $term['start_time'].'到'.$term['end_time'].','.$term['remark'].$html;
		
		$termhtml = '('.date("Y年n月j日",strtotime($term['start_time'])).'-'.date("Y年n月j日",strtotime($term['end_time'])).')'.$term['remark'];
	
		$retrun_arr = array(
				'tid' => $term['id'],
				'term_title' => $term['title'],
				'title' => $html,
				'value' => $total,
				'minititle' => $minititle,
				'minihtml' => $minihtml,
				'termhtml' =>$termhtml
		);
		return $retrun_arr;
	}
	
	
	/**
	 * 获取课程的学期、课程的收费信息
	 * @param unknown $term
	 * @param unknown $classtype
	 * @param unknown $status
	 */
	public function get_xuqi_lesson_info($tid,$lid,$status){
		$ct = $this->lesson->where(array('id'=>$lid))->relation(true)->find();
		$classtype = $ct['classtype'];
		
		$classtype['target1'] == $classtype['target2'] ? $tar = $classtype['target1'].'岁' : $tar = $classtype['target1'].'-'.$classtype['target2'].'岁';
		
		$term = $this->m->where(array('id'=>$tid))->find();
		
		if($term['studyyear_count'] == 2){
			//一个学年
			$total = $classtype['total'];
			$minititle = $term['title'];
			//$html = $classtype['title'].'('.$tar.')：一个学年学费'.$total.'元。';
			$html = '学费'.$total.'元，';
			//材料费
			if($classtype['materialcost']){
				$html.='材料费'.$classtype['materialcost'].'元';
				$total = $total+$classtype['materialcost'];
			}
			if($classtype['remark']){
				$html .= '，'.trim($classtype['remark']);
			}
			if($status == 'laosheng'){
				if($classtype['olddiscount']){
					//$html .= ' 老生学费优惠'.$classtype['olddiscount'].'元。'.trim($classtype['desc']);
					$total = $total - $classtype['olddiscount'];
					
					$desc = $this->get_remark_relation($term['id'], $classtype['id']);
					if(!$desc){
						$desc = trim($classtype['desc']);
					}
					if($desc){
						$html .= '，'.trim($desc).'老生学费九折合计'.$total.'元。';
					}else{
						$html .= '。老生学费九折合计'.$total.'元。';
					}
				};
			}else{
				if($classtype['discount']){
					$total = $total - $classtype['discount'];
					$html .= '。新生学费合计'.$total.'元。';
				}else{
					$html .= '。新生学费合计'.$total.'元。';
				}
			}		
		}else{
			//半个学年
			$total = $classtype['total_mid'];
			$minititle = '试学半年';
			$html = '学费'.$total.'元，';
			//材料费
			if($classtype['materialcost_mid']){
				$html.='材料费'.$classtype['materialcost_mid'].'元';
				$total = $total+$classtype['materialcost_mid'];
			}
			if($classtype['remark']){
				$html .= '，'.trim($classtype['remark']);
			}
			
			if($status == 'laosheng'){
				if($classtype['olddiscount_mid']){
					//$html .= ' 老生学费优惠'.$classtype['olddiscount_mid'].'元。'.trim($classtype['desc_mid']);
		
					$total = $total - $classtype['olddiscount_mid'];
					
					$desc = $this->get_remark_relation($term['id'], $classtype['id']);
					if(!$desc){
						$desc = trim($classtype['desc_mid']);
					}
					
					if($desc){
						$html .= '，'.trim($desc).'老生学费九折合计'.$total.'元。';
					}else{
						$html .= '。老生学费九折合计'.$total.'元。';
					}
				};
			}else{
				if($classtype['discount_mid']){
					$total = $total - $classtype['discount_mid'];
					$html .= '。新生学费九折合计'.$total.'元。';
				}else{
					$html .= '。学费合计'.$total.'元。';
				}
			}
			$term['title'] = $minititle;
		}
		$minihtml = $term['start_time'].'到'.$term['end_time'].','.$term['remark'].$html;
		//$html = $html.'<br/>'.date("Y年n月j日",strtotime($term['start_time'])).'-'.date("Y年n月j日",strtotime($term['end_time'])).','.$term['remark'];
		$termhtml = '('.date("Y年n月j日",strtotime($term['start_time'])).'-'.date("Y年n月j日",strtotime($term['end_time'])).')'.$term['remark'];
		
		$retrun_arr = array(
			'tid' => $term['id'],
			'term_title' => $term['title'],
			'title' => $html,
			'value' => $total,
			'minititle' => $minititle,
			'minihtml' => $minihtml,
			'termhtml' =>$termhtml
		);
		return $retrun_arr;
	}
	
	
	/**
	 * 获取学费信息
	 */
	public function getxueqi_new(){
		$studentstatus = I('studentstatus');//学生状态，老生or新生
		$lid = I('lid');
		
		
		$terms = A('Api/Term')->get_term_infos();

		foreach ($terms as $t){
			$item[] = $this->get_xuqi_lesson_info($t['id'],$lid,$studentstatus);
		}

	
		$result['title'] = '选择学期';
		$result['items'] = $item;
		$data = array(
				'status' => 1,
				'data' => $result,
		);
		$this->ajaxReturn($data);
	}
	
	/**
	 * 获取学费信息
	 */
	public function getxueqi_new_for_midbm(){
		$studentstatus = I('studentstatus');//学生状态，老生or新生
		$lid = I('lid');
		
		$cid = $this->lesson->where(array('id'=>$lid))->getField('cid');
		if($cid == '63'){
			//暑期班
			$terms = A('Api/Term')->get_term_infos_for_summer();
		}else{
			$terms = A('Api/Term')->get_term_infos_for_midbm();
		}
		
		foreach ($terms as $t){
			if($cid == '63'){
				//暑期班
				$item[] = $this->get_xuqi_lesson_summer($t['id'],$lid,$studentstatus);
			}else{
				$item[] = $this->get_xuqi_lesson_info($t['id'],$lid,$studentstatus);
			}
			
		}
	
	
		$result['title'] = '选择学期';
		$result['items'] = $item;
		$data = array(
				'status' => 1,
				'data' => $result,
		);
		$this->ajaxReturn($data);
	}
	
	//报名检查人员是否已满
	public function baomingcheck(){
		$tid = I('tid');
		$lid = I('lid');
		//循环判断学年人员
		$returndate = $this->get_baomingcheck($tid, $lid);
		$this->ajaxReturn($returndate);
	}
	
	public function get_baomingcheck($tid,$lid){
		$terminfo = R('Api/Term/get_term_by_id',array('id'=>$tid));
		$xuenian = $terminfo['studyyear'];
		$data = R('Api/Lessonapi/getnumber_by_xuenian',array('xuenian'=>$xuenian,'lid'=>$lid));
		$returndate = array('status'=>1,'info'=>'');
		if(!$data['bool']){
			$xnid = $data['xnid'];
			$info = M('YgclTermTime')->where(array('id'=>$xnid))->find();
			$html = '此班级('.$info['start_time'].'到'.$info['end_time'].')人数已报满,请选择其他班级或有特殊情况请联系校方递交申请';
			$returndate = array('status'=>0,'info'=>$html);
		}
		return $returndate;
	}
	
	
	/**
	 * 获取校区
	 */
	public function getxiaoqu_new(){
		$xiaoqu = F('Xiaoqu/xiaoqu');
		if(!$xiaoqu){
			$xiaoqu = $this->xiaoqu->where(array('status'=>1))->field('id,title,tel,address')->order('listorder desc,id desc')->select();
			F('XiaoQu/xiaoqu',$xiaoqu);
		}
	
		$data = array(
				'status' => 1,
				'data' => $xiaoqu,
		);
		$this->ajaxReturn($data);
	}

	
	/**
	 * 获取班级
	 */
	public function getclass_new() {
		$did = I('did');
		$class = F('Class/xq_'.$did.'/ClassData');
		
		//暑期班级---删除
		foreach ($class as $key=>$val){
			if($val['id'] == 63){
				unset($class[$key]);
			}
		}
		
		$data = array(
				'status' => 1,
				'data' => $class,
		);
		
		$this->ajaxReturn($data);
	}
	
     /**
	 * 获取班级--自定义报名
	 */
	public function getclass_new_for_midpay() {
		$did = I('did');
		$class = F('Class/xq_'.$did.'/ClassData');
		
		
		$data = array(
				'status' => 1,
				'data' => $class,
		);
		
		$this->ajaxReturn($data);
	}
	
	
	/**
	 * 获取课堂新
	 */
	public function getlesson_new(){
		$cid = I('cid');
		$info = $this->lesson->where(array('cid'=>$cid,'status'=>1))->relation(true)->order('listorder desc ,id desc')->select();
		foreach ($info as $in){
			$in['classtype']['target1'] == $in['classtype']['target2'] ? $tar = $in['classtype']['target1'] : $tar = $in['classtype']['target1']."-".$in['classtype']['target2'];
			
			$data[] = array(
				'id'=>$in['id'],
				'lessonname'=>$in['lessonname'],
				'lessoncode' => $in['lessoncode'],
				'tar' => $tar.'岁',
				'lessontype' => $in['classtype']['title'],
				'lessontime' => $in['lessontime']
			);
		}
		
		$lessondata = array(
				'status' => 1,
				'data' => $data,
		);
		$this->ajaxReturn($lessondata);
	}
	
	/**
	 * 判断是否是老生优先报名时间
	 * @param unknown $tid
	 */
	public function check_laosheng_time($tid){
		$now = Date('Y-m-d');
		$old_time = M('YgclTerm')->where(array('id'=>$tid))->getField('pay_for_old_time');
		if($now <= $old_time){
			return array('status'=>1,'old_time'=>$old_time);
		}else{
			return array('status'=>0,'old_time'=>'');
		}
	}
	
	//判断是否已报名学年
	public function check_xuenian_registered($student,$tel,$tid,$lid){
		$studyyear = M('YgclTerm')->where(array('id'=>$tid))->getField('studyyear');
		$studyyear_arr = explode(',',$studyyear);
		$b = array('status'=>1,'xuenian'=>'');
		foreach ($studyyear_arr as $sy){
			$map = array('student'=>$student,'tel'=>$tel,'xuenian'=>array('like','%'.$sy.'%'),'lid'=>$lid);
			$data = M('LessonStudentRelation')->where($map)->find();
			if($data){
				$b = array('status'=>0,'xuenian'=>$sy);
				break;
			}
		}
		return $b;
	}
	
	public function saveinfo(){
		I('type')?$type = I('type'):$type="baoming";
		$lid = I('lid');
		$tid = I('tid');
		$student = I('stuname');
		$tel = I('tel');
		$studentstatus = I('studentstatus');
		if(!$tid){
			$this->error('学期错误');
			exit();
		}
		if(!$lid){
			$this->error('班级错误');
			exit();
		}
		
		$total = I('total');
		if(!$total){
			$this->error('金额不能为空或为0');
			exit();
		}
		
		//课程报名
		if($type == 'baoming'){
			//判断是老生的报名时间
			$d = $this->check_laosheng_time($tid);
			if($d['status']){
				//根据学期id，班级id，获取学生
				$data = R('Api/Term/get_pre_next_xuexian_by_tid',array($tid));
				$old_students = R('Api/Student/get_old_student_by_tid_lid',array('xnid'=>$data['pre_xnid'],'lid'=>$lid));
				$old_count = count($old_students);
				$next_students = R('Api/Student/get_old_student_by_tid_lid',array('xnid'=>$data['next_xnid'],'lid'=>$lid));
				$number = M('YgclLesson')->where(array('id'=>$lid))->getField('number');
				//可添加新生的人数
				$num_for_student = $number - $old_count;
					
				$info = R('Api/Student/get_new_or_old_student',array('old_students'=>$old_students,'next_students'=>$next_students));
				//当前已添加新生的人数
				$count_xinsheng = count($info['new']);

				//老生判断
				if($studentstatus == 'laosheng'){
					$old_lids = R('Api/Student/get_old_student_lid',array('student'=>$student,'tel'=>$tel));
					if(in_array($lid,$old_lids)){
						if(!R('Api/Student/_check_student_in_pre_xuenian',array('old_students'=>$old_students,'student'=>$student,'tel'=>$tel))){
							if($num_for_student > 0 ){
								if($count_xinsheng >= $num_for_student){
									$this->error('此班级请在'.$d['old_time'].'之后报名');
									exit();
								}
							}else{
								$this->error('此班级请在'.$d['old_time'].'之后报名');
								exit();
							}
						}
					}else{
						if($num_for_student > 0){
							if($count_xinsheng >= $num_for_student){
								$this->error('此班级请在'.$d['old_time'].'之后报名');
								exit();
							}
						}else{
							$this->error('此班级请在'.$d['old_time'].'之后报名');
							exit();
						}
					}
			
				}

				//新生判断
				if($studentstatus == 'xinsheng'){
					if($num_for_student > 0){
						if($count_xinsheng >= $num_for_student){
							$this->error('此班级请在'.$d['old_time'].'之后报名');
							exit();
						}
					}else{
						$this->error('此班级请在'.$d['old_time'].'之后报名');
						exit();
					}
				}
			}
		}
		
		
		
		//判断所报学期是否有交集报名
		$reg_status = $this->check_xuenian_registered($student, $tel, $tid,$lid);
		if(!$reg_status['status']){
			$xuenian = $reg_status['xuenian'];
			$termtime_info = R('Api/Termtime/get_termtime_info_by_xuenian',array($xuenian));
			$html = '您已经报名'.$termtime_info['title'].'('.$termtime_info['start_time'].'到'.$termtime_info['end_time'].'),不要重复报名';
			$this->error($html);
			exit();
		}
		
		//班级人数判断
		$status = $this->get_baomingcheck($tid,$lid);
		if($status['status']){
			$data = array(
					'uid'     => I('uid'),
					'ddbh'    => date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8),
					'type'    => $type,
					'stuname' => I('stuname'),
					'birthday' => I('birthday'),
					'tel'     => I('tel'),
					'jzxm'    => I('jzxm'),
					'studentstatus' => I('studentstatus'),
					'termid'  => $tid,
					'did' => I('did'),
					'cid' => I('cid'),
					'lid' => $lid,
					'total'   => $total,
					'create_time' => Date('Y-m-d H:i:s'),
					'update_time' => Date('Y-m-d H:i:s'),
					'token_time' => time()+60*30, //有效期30分钟
			);
			$this->order->create($data);
			$id = $this->order->add();
			if($id){
				$this->_save_order_detail($id,I('remark'));

				//班级人数加1--
				//R('Api/Lessonapi/lesson_number_inc',array('tid'=>$tid,'lid'=>$lid));
			}
			$this->ajaxReturn(array('status'=>1,'data'=>$id));
		}else{
			$this->error($status['info']);
		}
	}
	
	
	Public function _save_order_detail($orderid,$remark){
		$info = $this->order->where(array('id'=>$orderid))->relation(true)->find();
		$lesson_xueqi_info= $this->get_xuqi_lesson_info($info['termid'],$info['lesson']['id'],$info['studentstatus']);
		$data = array(
				'orderid' => $orderid,
				'info' => '费用：'.$info['total'].'('.$lesson_xueqi_info['minihtml'].')',
				'remark' => $remark
		);
		$m = D('YgclOrderDetail');
		$m->create($data);
		$m->add();
	}
	
	Public function _save_order_detail2($orderid,$termid,$did,$cid,$lid,$info,$remark){
		$terminfo = $this->m->where('id = '.$termid)->find();
		$xiaoqu = $this->xiaoqu->where(array('id'=>$did))->getField('title');
		$banji = $this->class->where(array('id'=>$cid))->getField('title');
		$lesson = $this->lesson->where(array('id'=>$lid))->relation(true)->find();
		$data = array(
				'orderid' => $orderid,
				'term'    => $terminfo['title'],
				'start_time'  => $terminfo['start_time'],
				'end_time'    => $terminfo['end_time'],
				'xiaoqu'  => $xiaoqu,
				'banji'   => $banji,
				'lessontype' => $lesson['classtype']['title'],
				'lessontarget1' => $lesson['classtype']['target1'],
				'lessontarget2' => $lesson['classtype']['target2'],
				'lessonname' => $lesson['lessonname'],
				'lessoncode' => $lesson['lessoncode'],
				'lessontime' => $lesson['lessontime'],
				'info' => $info,
				'remark' => $remark
		);
		$m = D('YgclOrderDetail');
		$m->create($data);
		$m->add();
	}
	
	//保存体验数据
	public function savetiyan(){
		if($_POST){
			//if(!$this->check_tiyan_number($_POST['lid'])){
			//	$this->ajaxReturn(array('status'=>0,'data'=>'该班级人数已满，请选择其他的班级体验课程'));
			//	exit();
			//}
			$check_tiyan = R('Api/Tiyan/check_tiyan',array('uid'=>$_POST['uid']));
			if($check_tiyan){
				$_POST['fee'] = 90;
			}else{
				$_POST['fee'] = 0;
			}
			
			$_POST['create_time'] =  $_POST['update_time'] =Date('Y-m-d H:i:s');
			$this->tiyan->create();
			$id = $this->tiyan->add();
			if($_POST['fee']){
				$data = array(
						'uid'     => $_POST['uid'],
						'ddbh'    => date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8),
						'type'    => 'tiyan',
						'objectid'=> $id,
						'objectinfo'=> '体验课,校区:'.$_POST['xiaoqu'].',课程:'.$_POST['banji'],
						'total'   => $_POST['fee'],
						'create_time' => Date('Y-m-d H:i:s'),
						'update_time' => Date('Y-m-d H:i:s'),
						'token_time' => time()+60*30, //有效期30分钟
				);
				$orderid = $this->order->add($data);
				$map['id'] = $id;
				$map['orderid'] = $orderid;
				$this->tiyan->save($map);
				$this->ajaxReturn(array('status'=>1,'data'=>$orderid));
				exit();
			}
			$this->ajaxReturn(array('status'=>1,'data'=>''));
		}
	}
	
	
	//保存打赏数据
	public function savedashang(){
		if(IS_POST){
			$fee = rand(0,500)/100;
			$tcid = $_POST['tcid'];
			$teacherinfo = $this->teacher->where(array("id"=>$tcid))->relation(true)->find();
			$data = array(
					'uid'     => $_POST['uid'],
					'ddbh'    => date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8),
					'type'    => 'dashang',
					'objectid'=> $tcid,
					'objectinfo'=> '给老师（'.$teacherinfo['users']['realname'].'）打赏',
					'did' => $_POST['did'],
					'total'   => $fee,
					'create_time' => Date('Y-m-d H:i:s'),
					'update_time' => Date('Y-m-d H:i:s'),
					'token_time' => time()+60*30, //有效期30分钟
			);
			$orderid = $this->order->add($data);
			$this->ajaxReturn(array('status'=>1,'data'=>$orderid));
		}else{
			$this->ajaxReturn(array('status'=>1,'data'=>'提交失败'));
		}
	}
	
	//判断体验人数是否超出
	public function check_tiyan_number($lid){
		$data  = R('Api/Lessonapi/check_tiyan',array('$tid'));
		if($data['bool']){
			return true;
		}else{
			return false;
		}
	}
	
	//保存其他体验数据
	public function saveqitatiyan(){
		if($_POST){
			$_POST['create_time'] =  $_POST['update_time'] =Date('Y-m-d H:i:s');
			$this->qitatiyan->create();
			$id = $this->qitatiyan->add();
			if($_POST['fee']){
				$data = array(
						'uid'     => $_POST['uid'],
						'ddbh'    => date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8),
						'type'    => 'qitatiyan',
						'objectid'=> $id,
						'objectinfo'=> '其他体验课,课程:'.$_POST['kecheng'],
						'total'   => $_POST['fee'],
						'create_time' => Date('Y-m-d H:i:s'),
						'update_time' => Date('Y-m-d H:i:s'),
						'token_time' => time()+60*30, //有效期30分钟
				);
				$orderid = $this->order->add($data);
				$map['id'] = $id;
				$map['orderid'] = $orderid;
				$this->qitatiyan->save($map);
				$this->ajaxReturn(array('status'=>1,'data'=>$orderid));
				exit();
			}
			$this->ajaxReturn(array('status'=>1,'data'=>''));
		}
	}
	
	public function dianzai(){
		$id = I("id");
		$type = I('type');
		$uid = I('uid');
		if($this->dianzai->where(array('uid'=>$uid,'objectid'=>$id,'type'=>$type))->find()){
			$this->dianzai->where(array('uid'=>$uid,'objectid'=>$id,'type'=>$type))->delete();
			if($type == 'xiaoqu'){
				$this->xiaoqu->where(array('id'=>$id))->setDec('dianzai');
			}
			if($type == 'banji'){
				$this->class->where(array('id'=>$id))->setDec('dianzai');
			}
			if($type == 'teacher'){
				$this->teacher->where(array('id'=>$id))->setDec('dianzai');
			}
			$this->ajaxReturn('点赞');
			
		}else{
			$data = array(
				'uid' => $uid,
				'objectid' => $id,
				'type' => $type,
				'create_time' => Date('Y-m-d H:i:s'),
				'update_time' => Date('Y-m-d H:i:s'),
			);
			$this->dianzai->create($data);
			$this->dianzai->add();
			if($type == 'xiaoqu'){
				$this->xiaoqu->where(array('id'=>$id))->setInc('dianzai');
			}
			if($type == 'banji'){
				$this->class->where(array('id'=>$id))->setInc('dianzai');
			}
			if($type == 'teacher'){
				$this->teacher->where(array('id'=>$id))->setInc('dianzai');
			}
			$this->ajaxReturn('取消');
		}
	}
	
	//work评价
	public function saveworkpingjia(){
		if(IS_POST){
			$data = array(
				'uid' => I('uid'),
				'wid' => I('wid'),
				'pingjia' => I('pingjia'),
				'remark' => I('remark'),
				'create_time' => Date('Y-m-d H:i:s'),
				'update_time' => Date('Y-m-d H:i:s'),
			);
			$m = D('YgclPingjia');
			$m->create($data);
			if($m->add()){
				$this->success('提交成功');
			}else{
				$this->error('提价失败');
			}
		}
	}
	
	public function delpingjia(){
		$id = I('id');
		if(D('YgclPingjia')->where(array('id'=>$id))->delete()){
			$this->success('删除成功');
		}else{
			$this->error('删除失败');
		}
	}
	
	//老师评价
	public function saveteaacherpingjia(){
		if(IS_POST){
			$data = array(
					'cid' => I('cid'),
					'uid' => I('uid'),
					'teacher' => I('teacherid'),
					'pingjia' => I('pingjia'),
					'remark' => I('remark'),
					'create_time' => Date('Y-m-d H:i:s'),
					'update_time' => Date('Y-m-d H:i:s'),
			);
			$m = D('YgclPingjiaTeacher');
			$m->create($data);
			if($m->add()){
				$this->success('提交成功');
			}else{
				$this->error('提价失败');
			}
		}
	}
	
	public function delpingjiateacher(){
		$id = I('id');
		if(D('YgclPingjiaTeacher')->where(array('id'=>$id))->delete()){
			$this->success('删除成功');
		}else{
			$this->error('删除失败');
		}
	}

}